package com.hjj.formatter;

import org.springframework.format.FormatterRegistrar;
import org.springframework.format.FormatterRegistry;

import java.util.HashMap;

public class MyFormatterRegistrar implements FormatterRegistrar {
    private String datePattern;
    private String errorMsg;

    // HashMap是用于对个参数的传递
    /*private HashMap<String, Object> hashMap;

    public MyFormatterRegistrar(HashMap<String, Object> hashMap) {
        this.datePattern = (String) hashMap.get("datePattern");
        this.errorMsg = (String) hashMap.get("errorMsg");
    }*/

    public MyFormatterRegistrar(String datePattern, String errorMsg) {
        this.datePattern = datePattern;
        this.errorMsg = errorMsg;
    }

    @Override
    public void registerFormatters(FormatterRegistry registry) {
        registry.addFormatter(new MyDateFormatter(datePattern, errorMsg));
    }
}
